package com.future.enable;

import com.future.interceptor.AsyncAopAdvice;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Role;

/**
 * Spring AOP分为两种实现
 *     基于AspectJ注解
 *     基于Spring AOP思想，也就是Advice 、 Pointcut 、 Advisor 这个三个，对应MethodInterceptor、AbstractBeanFactoryPointcutAdvisor、StaticMethodMatcherPointcut 三个类。
 *
 * Import注解注入Bean的方式有如下三种
 * 基于Configuration Class 实现ImportAware
 * 主要用来配置AOP相关的类实例
 */
public class AsyncConfig {

    @Bean("com.future.enable.AsyncAdvisor")
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public AsyncAdvisor createAsyncAdvisor(AsyncAopAdvice asyncAdvice, AsyncPointcut asyncPointcut) {
        AsyncAdvisor AsyncAdvisor = new AsyncAdvisor(asyncPointcut); //注入切点
        AsyncAdvisor.setAdvice(asyncAdvice); //添加拦截器
        return AsyncAdvisor;
    }

}
